gtkcombobox: Use controller to handle combobox keybindings in menus
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 26 Jun 2018 11:35:26 +0000 (13:35 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 30 Jul 2018 11:14:12 +0000 (13:14 +0200)
Instead of an ::event callback.

gtk/gtkcombobox.c
gtk/ui/gtkcombobox.ui

index f5844ad5720a45aa8e79f7fd00949bf0b14fdadb..caf4042640c8738995d4772b492ac10a98d98bf1 100644 (file)
@@ -39,6 +39,7 @@
 #include "gtktogglebutton.h"
 #include "gtktreemenu.h"
 #include "gtktypebuiltins.h"
+#include "gtkeventcontrollerkey.h"
 
 #include "a11y/gtkcomboboxaccessible.h"
 
@@ -275,9 +276,11 @@ static void     gtk_combo_box_menu_activate        (GtkWidget        *menu,
                                                     const gchar      *path,
                                                     GtkComboBox      *combo_box);
 static void     gtk_combo_box_update_sensitivity   (GtkComboBox      *combo_box);
-static gboolean gtk_combo_box_menu_event           (GtkWidget        *widget,
-                                                    GdkEvent         *event,
-                                                    gpointer          data);
+static gboolean gtk_combo_box_menu_key (GtkEventControllerKey *key,
+                                        guint                  keyval,
+                                        guint                  keycode,
+                                        GdkModifierType        modifiers,
+                                        GtkComboBox           *combo_box);
 static void     gtk_combo_box_menu_popup           (GtkComboBox      *combo_box);
 
 /* cell layout */
@@ -843,7 +846,7 @@ gtk_combo_box_class_init (GtkComboBoxClass *klass)
   gtk_widget_class_bind_template_child_internal_private (widget_class, GtkComboBox, popup_widget);
   gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_button_toggled);
   gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_activate);
-  gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_event);
+  gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_key);
   gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_show);
   gtk_widget_class_bind_template_callback (widget_class, gtk_combo_box_menu_hide);
 
@@ -1931,21 +1934,26 @@ gtk_combo_box_model_row_changed (GtkTreeModel     *model,
 }
 
 static gboolean
-gtk_combo_box_menu_event (GtkWidget *widget,
-                          GdkEvent  *event,
-                          gpointer   data)
+gtk_combo_box_menu_key (GtkEventControllerKey *key,
+                        guint                  keyval,
+                        guint                  keycode,
+                        GdkModifierType        modifiers,
+                        GtkComboBox           *combo_box)
 {
-  GtkComboBox *combo_box = GTK_COMBO_BOX (data);
+  GtkWidget *widget;
+  GdkEvent *event;
+
+  widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (key));
+  event = gtk_get_current_event ();
 
   if (!gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *)event))
     {
-      /* The menu hasn't managed the
-       * event, forward it to the combobox
-       */
-      return gtk_bindings_activate_event (G_OBJECT (combo_box), (GdkEventKey *)event);
+      gtk_event_controller_key_forward (key, GTK_WIDGET (combo_box));
     }
 
-  return GDK_EVENT_PROPAGATE;
+  g_object_unref (event);
+
+  return TRUE;
 }
 
 /*
index ef2d29c9dfa7e67d4bda28d9b9fc3a6f3246bef0..cf6a81fd51d8e59815f931b8ca7ef777ad19d58d 100644 (file)
   <object class="GtkTreeMenu" id="popup_widget">
     <property name="cell-area">area</property>
     <signal name="menu-activate" handler="gtk_combo_box_menu_activate" swapped="no"/>
-    <signal name="event" handler="gtk_combo_box_menu_event" swapped="no"/>
     <signal name="show" handler="gtk_combo_box_menu_show" swapped="no"/>
     <signal name="hide" handler="gtk_combo_box_menu_hide" swapped="no"/>
+    <child>
+      <object class="GtkEventControllerKey">
+        <signal name="key-pressed" handler="gtk_combo_box_menu_key" swapped="no"/>
+        <signal name="key-released" handler="gtk_combo_box_menu_key" swapped="no"/>
+      </object>
+    </child>
   </object>
 </interface>